﻿using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using Volo.Abp.Specifications;
using static PHMEE.PHMEEAdminPermissions;

namespace PHMEE
{
    /// <summary>
    /// 测点-船舶-工艺契约
    /// </summary>
    public class PointSpecificationVessel : Specification<Point>
    {
        public Guid VesselId { get; set; }

        public PointSpecificationVessel(Guid vesselId)
        {
            VesselId = vesselId;
        }

        public override Expression<Func<Point, bool>> ToExpression()
        {
            return item => item.Category == PointCategoryEnum.Technology &&
                           item.OwnerId == VesselId &&
                           item.OwnerType == nameof(Vessel);
        }
    }

    /// <summary>
    /// 测点-机组-工艺契约
    /// </summary>
    public class PointSpecificationUnit : Specification<Point>
    {
        public Guid UnitId { get; set; }

        public PointSpecificationUnit(Guid unitId)
        {
            UnitId = unitId;
        }

        public override Expression<Func<Point, bool>> ToExpression()
        {
            return item => item.Category == PointCategoryEnum.Technology &&
                           item.OwnerId == UnitId &&
                           item.OwnerType == nameof(Unit);
        }
    }

    /// <summary>
    /// 测点-设备-工艺契约
    /// </summary>
    public class PointSpecificationEquipment : Specification<Point>
    {
        public Guid EquipmentId { get; set; }

        public PointSpecificationEquipment(Guid equipmentId)
        {
            EquipmentId = equipmentId;
        }

        public override Expression<Func<Point, bool>> ToExpression()
        {
            return item => item.Category == PointCategoryEnum.Technology &&
                           item.OwnerId == EquipmentId &&
                           item.OwnerType == nameof(Equipment);
        }
    }

    /// <summary>
    /// 测点-设备集合-工艺契约
    /// </summary>
    public class PointSpecificationEquipments : Specification<Point>
    {
        public List<Guid> EquipmentIds { get; set; } = new List<Guid>();

        public PointSpecificationEquipments(List<Guid> equipmentIds)
        {
            EquipmentIds = equipmentIds;
        }

        public override Expression<Func<Point, bool>> ToExpression()
        {
            return item => item.Category == PointCategoryEnum.Technology &&
                           EquipmentIds.Contains(item.OwnerId) &&
                           item.OwnerType == nameof(Equipment);
        }
    }

    /// <summary>
    /// 测点-部件-工艺契约
    /// </summary>
    public class PointSpecificationComponent : Specification<Point>
    {
        public Guid ComponentId { get; set; }

        public PointSpecificationComponent(Guid componentId)
        {
            ComponentId = componentId;
        }

        public override Expression<Func<Point, bool>> ToExpression()
        {
            return item => item.Category == PointCategoryEnum.Technology &&
                           item.OwnerId == ComponentId &&
                           item.OwnerType == nameof(Component);
        }
    }

    /// <summary>
    /// 测点-部件集合-工艺契约
    /// </summary>
    public class PointSpecificationComponents : Specification<Point>
    {
        public List<Guid> ComponentIds { get; set; } = new List<Guid>();

        public PointSpecificationComponents(List<Guid> componentIds)
        {
            ComponentIds = componentIds;
        }

        public override Expression<Func<Point, bool>> ToExpression()
        {
            return item => item.Category == PointCategoryEnum.Technology &&
                           ComponentIds.Contains(item.OwnerId) &&
                           item.OwnerType == nameof(Component);
        }
    }

}
